package com.leetcode.p100;

import com.bean.TreeNode;
import com.utils.TreeUtils;

public class Test104 {

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(help(root.left, 1), help(root.right, 1));
    }

    private int help(TreeNode root, int depth) {
        if (root == null) {
            return depth;
        }
        return Math.max(help(root.left, depth + 1), help(root.right, depth + 1));
    }

    public static void main(String[] args) {
        TreeNode root = TreeUtils.buildTree();
        TreeUtils.showTree(root);

        Test104 test = new Test104();
        int result = test.maxDepth(root);
        System.out.println(result);
    }

}
